package cn.lger.icollege.dao;

import cn.lger.icollege.entity.Attendance;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.security.access.method.P;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Code that Changed the World
 * Pro said
 * Created by Pro on 2018-04-14.
 */
@Repository
public interface AttendanceDao extends JpaRepository<Attendance, String> {

    Page<Attendance> findAllByStudentUsername(Pageable pageable, String username);

    void deleteByTeacherUsername(String username);

//    void deleteByTeacherUsernameAndClassroomClassId(String username,Long classId );

    Page<Attendance> findAllByTeacherUsername(Pageable pageable, String username);

//    Page<Attendance> findAllByTeacherUsernameAndClassroomClassId(Pageable pageable, String username, Long classId);

    List<Attendance> findAllByTeacherUsernameAndStudentUsername(String teacherUsername, String studentUsername, Sort sort);

    Page<Attendance> findAllByStudentNameAndTeacherName(Pageable pageable,  String studentUsername, String teacherUsername);

    Attendance findByIdAndTeacherUsername(String id, String teacherUsername);

    @Query("select count(a.id) from Attendance a where a.teacher.username = :teacherUsername and a.student.username = :studentUsername and a.attendance = :attendanceEnum")
    int findAttendanceCountByTeacherUsernameAndStudentUsernameAndAttendance(@Param("teacherUsername") String teacherUsername,@Param("studentUsername") String studentUsername,@Param("attendanceEnum") Attendance.AttendanceEnum attendanceEnum);

}
